package com.weiwei.diancan.adapter;

import android.graphics.Color;
import android.graphics.Paint;
import android.text.Spannable;
import android.text.SpannableStringBuilder;
import android.text.style.StrikethroughSpan;
import android.widget.TextView;

import com.weiwei.diancan.R;
import com.weiwei.diancan.bean.OrderWapper;

import java.util.List;

import weiwei.com.weiweilibrary.adapter.BaseQuickAdapter;
import weiwei.com.weiweilibrary.holder.BaseViewHolder;

/**
 * Created by BMW on 2016/11/25.
 */
public class PayAdapter extends BaseQuickAdapter<OrderWapper> {

    public PayAdapter(List<OrderWapper> data) {
        super(R.layout.item_pay, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, OrderWapper item, int position) {
        TextView tv_name = helper.getView(R.id.tv_name);
        TextView tv_num = helper.getView(R.id.tv_num);

        if(item.getOrder_state().equals("1")){
            tv_name.setTextColor(Color.parseColor("#B41B1B"));
            tv_num.setTextColor(Color.parseColor("#B41B1B"));
        }else if(item.getOrder_state().equals("2")){
            tv_name.setTextColor(Color.parseColor("#777777"));
            tv_num.setTextColor(Color.parseColor("#777777"));
            tv_name.getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG);
            tv_num.getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG);
        }

        tv_name.setText(item.getOrder_no()+"("+item.getTime()+")");
        tv_num.setText("¥"+item.getOrder_price());
//        mode6(tv_name,"20161124001(12:45:24)");
//        mode6(tv_num,"¥9999.50");

    }

    /**
     * 设置删除线
     * @param tv
     * @param s
     */
    private void mode6(TextView tv,String s) {
        SpannableStringBuilder spannableString = new SpannableStringBuilder();
        spannableString.append(s);
        StrikethroughSpan strikethroughSpan = new StrikethroughSpan();
        spannableString.setSpan(strikethroughSpan, 0, 8, Spannable.SPAN_EXCLUSIVE_INCLUSIVE);
       tv.setText(spannableString);
    }
}
